package com.fzkjjt.easyexceldemo.config;

import com.github.xiaoymin.swaggerbootstrapui.annotations.EnableSwaggerBootstrapUI;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @program: easyexcel-demo
 * @description:
 * @author: FangZhen
 * @create: 2020-04-17 17:03
 **/
@Configuration
@EnableSwagger2
@EnableSwaggerBootstrapUI
@ConditionalOnProperty(prefix = "swagger2", name = "basePackage")
public class Swagger2Config {

    @Value("${swagger2.basePackage:com.yexx}")
    private String basePackage;

    @Value("${swagger2.version:1.0.0}")
    private String version;

    @Value("${swagger2.title:Yexx Optms Api Doc}")
    private String title;

    @Value("${swagger2.description:This is a demo description for yexx's optms api doc.}")
    private String description;

    @Value("${swagger2.contact.name:minz}")
    private String name;

    @Value("${swagger2.contact.url:https://gitee.com/minzzzZ}")
    private String url;

    @Value("${swagger2.contact.email:myleszelic@outlook.com}")
    private String email;

    @Bean
    public Docket petApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage(basePackage)) //指定提供接口所在的基包
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title(title)
                .contact(new Contact(name, url, email))
                .version(version)
                .description(description)
                .build();
    }
}
